package com.wgts.wgts.mvp.view.activity.tasklobby;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.TaskListEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 * 会员任务
 *
 */public class TaskVipAdapter extends RecyclerView.Adapter<TaskVipAdapter.ViewHold> {
    private Context context;
    private List<TaskListEntity.Task> list;
    private onClickListern onClickListern;

    public TaskVipAdapter(Context context, List<TaskListEntity.Task> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.wgts_task_adapter_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, final int i) {
        viewHold.taskTitle.setText(list.get(i).produceName);
        viewHold.taskContent.setText(list.get(i).taskName);
        viewHold.awardText.setText("奖励" + list.get(i).money + "元");
        switch (list.get(i).status){
            case "ACTIVE":
                viewHold.taskStatusText.setText("进行中");
                break;
            case "PENDING":
                viewHold.taskStatusText.setText("做任务");
                break;
        }
        viewHold.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListern != null){
                    onClickListern.onClick(v, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.task_title)
        TextView taskTitle;
        @BindView(R.id.task_content)
        TextView taskContent;
        @BindView(R.id.award_text)
        TextView awardText;
        @BindView(R.id.task_status_text)
        TextView taskStatusText;
        @BindView(R.id.task_status_ly)
        LinearLayout taskStatusLy;
        private View itemView;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface onClickListern{
        void onClick(View view, int position);
    }

    public void setOnClickListern(onClickListern onClickListern){
        this.onClickListern = onClickListern;
    }
}
